package com.imti.mall.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.imti.mall.model.pms.pojo.PmsProduct;
import com.imti.mall.model.pms.vo.PmsProductParam;
import com.imti.mall.product.mapper.PmsProductMapperS;
import com.imti.mall.product.service.PmsProductServiceS;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PmsProductServiceImplS extends ServiceImpl<PmsProductMapperS,PmsProduct> implements PmsProductServiceS {
    @Resource
    private PmsProductMapperS pmsProductMapper;


    @Override
    public List<PmsProduct> fetchList(PmsProductParam pmsProductParam) {
        QueryWrapper queryWrapper=new QueryWrapper<>();
        if (null!=pmsProductParam.getName()){
            queryWrapper.like("name",pmsProductParam.getName());
        }

        Map map=new HashMap();
        //map.put("publish_status",)
        map.put("publish_status",pmsProductParam.getPublishStatus());
        map.put("verify_status",pmsProductParam.getVerifyStatus());
        map.put("product_sn",pmsProductParam.getProductSn());
        map.put("brand_id",pmsProductParam.getBrandId());
        map.put("product_category_id",pmsProductParam.getProductCategoryId());
        queryWrapper.allEq(map,false);
        return pmsProductMapper.selectList(queryWrapper);
    }

    @Override
    public int updatePublishStatus(List<Integer> ids, Integer publishStatus) {
        UpdateWrapper<PmsProduct> updateWrapper=new UpdateWrapper<>();
        updateWrapper.in("id",ids) ;
        updateWrapper.set("publish_status",publishStatus);

        PmsProduct pmsProduct=new PmsProduct();
        return pmsProductMapper.update(pmsProduct,updateWrapper);
    }

    @Override
    public int updateNewStatus(List<Integer> ids, Integer newStatus) {
        UpdateWrapper<PmsProduct> updateWrapper=new UpdateWrapper<>();
        updateWrapper.in("id",ids) ;
        updateWrapper.set("new_status",newStatus);

        PmsProduct pmsProduct=new PmsProduct();
        return pmsProductMapper.update(pmsProduct,updateWrapper);
    }

    @Override
    public int updateRecommendStatus(List<Integer> ids, Integer recommandStatus) {
        UpdateWrapper<PmsProduct> updateWrapper=new UpdateWrapper<>();
        updateWrapper.in("id",ids) ;
        updateWrapper.set("recommand_status",recommandStatus);

        PmsProduct pmsProduct=new PmsProduct();
        return pmsProductMapper.update(pmsProduct,updateWrapper);
    }

    @Override
    public int updateDeleteStatus(List<Integer> ids, Integer deleteStatus) {
        UpdateWrapper<PmsProduct> updateWrapper=new UpdateWrapper<>();
        updateWrapper.in("id",ids) ;
        updateWrapper.set("delete_status",deleteStatus);

        PmsProduct pmsProduct=new PmsProduct();
        return pmsProductMapper.update(pmsProduct,updateWrapper);
    }

    @Override
    public PmsProduct getProduct(Integer id) {
        return pmsProductMapper.selectById(id);
    }


}
